package com.lx.oms.controller.controller;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lx.oms.common.annotation.SysLog;
import com.lx.oms.common.controller.AbstractController;
import com.lx.oms.common.entity.R;
import com.lx.oms.controller.entity.SysCategoryEntity;
import com.lx.oms.controller.service.SysCategoryService;

/**
 * 类别
 * @author houzhong
 *
 */
@RestController
@RequestMapping("/sys/category")
public class SysCategoryController extends AbstractController {
	
	@Autowired
	private SysCategoryService sysCategoryService;
	
	/**
	 * 根据父级code查询子节点，子区域列表
	 * @param params
	 * @return
	 */
	@RequestMapping("/list")
	public R list(@RequestBody Map<String, Object> params) {
		return sysCategoryService.listCategoryByParentId(params);
	}
	
	/**
	 * 根据父级code查询子节点，树形目录
	 * @return
	 */
	@RequestMapping("/select")
	public List<SysCategoryEntity> select(@RequestParam String categoryId) {
		return sysCategoryService.listCategoryByParentId(categoryId);
	}
	
	@RequestMapping("/selectParentId")
	public List<SysCategoryEntity> selectParentId(String parentId,String type) {
		return sysCategoryService.getCategoryByParentId(parentId,type);
	}
	
		
	/**
	 * 新增
	 * @param sysCategory
	 * @return
	 */
	@SysLog("新增类别")
	@RequestMapping("/save")
	public R save(@RequestBody SysCategoryEntity sysCategory) {
		return sysCategoryService.saveCategory(sysCategory);
	}
	
	/**
	 * 根据id查询详情
	 * @param id
	 * @return
	 */
	@RequestMapping("/info")
	public R getById(@RequestBody String id) {
		return sysCategoryService.getCategoryById(new BigInteger(id));
	}
	
	/**
	 * 修改
	 * @param sysCategory
	 * @return
	 */
	@SysLog("修改类别")
	@RequestMapping("/update")
	public R update(@RequestBody SysCategoryEntity sysCategory) {
		return sysCategoryService.updateCategory(sysCategory);
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@SysLog("删除类别")
	@RequestMapping("/remove")
	public R batchRemove(@RequestBody String[] id) {
		return sysCategoryService.batchRemoveCategory(id);
	}
	
}
